﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using BloomsburyBanHang.DAO;

namespace BloomsburyBanHang
{
    public partial class Admin_ThemSanPham : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }



        protected void Button1_Click(object sender, EventArgs e)
        {
            string ten = txt_Ten.Text;
            string giaBia = txt_GiaBia.Text;
            string giaGoc = txt_GiaGoc.Text;
            string soLuong = txt_SoLuong.Text;
            DateTime ngayPhatHanh = this.Calendar1.SelectedDate;
            int maKieu = Convert.ToInt32(List_Loai.SelectedValue);
            int maTheLoai = Convert.ToInt32(List_LinhVuc.SelectedValue);
            int maTacGia = Convert.ToInt32(List_TacGia.SelectedValue);
            int maNXB = Convert.ToInt32(List_NXB.SelectedValue);
            int maKhuyenMai = Convert.ToInt32(List_KhuyenMai.SelectedValue);
            //int maTinhTrang = Convert.ToInt32(List_TinhTrang.SelectedValue);
            string hinhanh = "";
            if (FileUpload1.HasFile)
            {
                try
                {
                    string filename = Path.GetFileName(FileUpload1.FileName);
                    FileUpload1.SaveAs(Server.MapPath("~/images/") + filename);
                    //Label2.Text = "Upload status: File uploaded!";
                    hinhanh = Server.MapPath("~/images/") + filename;
                }
                catch (Exception ex)
                {
                    Label3.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
                }
            }
            int kq = SanPhamDAO.ThemSanPham(ten, maKieu, maTheLoai, maTacGia, "", ngayPhatHanh, Convert.ToInt32(soLuong), Convert.ToDouble(giaBia), maKhuyenMai, maNXB, hinhanh);
            if (kq == 1)
                Label3.Text = "Them San Pham Thanh Cong!!!";

        }

        protected void List_KhuyenMai_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}